package com.wujilin.okra.activity;

import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;

import com.wujilin.okra.R;

/**
 * The activity class contains only one fragment.
 * 
 * @author Belin Wu
 */
public abstract class SingleFragmentActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single);
        
        ActionBar actionBar = getActionBar();
        
        actionBar.setDisplayHomeAsUpEnabled(true);
        
        Fragment fragment = getFragment(R.id.container);
        if (fragment == null) {
        	fragment = onCreateFragment();
        	getFragmentManager().beginTransaction()
        		.add(R.id.container, fragment)
        		.commit();
        }
    }

    /**
     * Call the creating of fragment hosted in this activity.
     * 
     * @return The fragment
     */
    public abstract Fragment onCreateFragment();
}
